from typing import List


class Solution:
    def minimizeArrayValue(self, nums: List[int]) -> int:
        left = 1
        right = 10001
        while left + 1 < right:
            mid = (left + right) // 2
            if self.check(nums, mid):
                right = mid
            else:
                left = mid
        return right

    def check(self, nums: List[int], val: int):
        nums_r = nums.copy()
        nums_r.reverse()
        for i in range(0, len(nums_r) - 1):
            if nums_r[i] > val:
                nums_r[i + 1] += nums_r[i] - val
                nums_r[i] = val
        return nums_r[-1] <= val
